/**
 * 生成UUID函数
 * @returns {string}
 */
export function uuid () {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    const r = Math.random() * 16 | 0
    const v = c === 'x' ? r : (r & 0x3 | 0x8)
    return v.toString(16)
  })
}

/**
 * 数组中插入元素
 * @param {Array} arr - 数组
 * @param {Object} ele - 要插入的对象
 * @param {number} idx - 插入元素的位置
 */
export function inertElement2Array (arr, ele, idx) {
  if (idx > arr.length - 1 || idx < 0) throw new Error('index error')
  let newArr = arr.concat([])
  newArr.length = newArr.length + 1
  newArr[idx] = ele
  for (let i = idx + 1; i < newArr.length; i++) {
    newArr[i] = arr[i - 1]
  }
  return newArr
}
